﻿using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Power.ViewModel.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Power.View.Report
{
    /// <summary>
    /// 检查井检查情况汇总表
    /// </summary>
    public partial class CheckTable : UserControl
    {
        public CheckTable()
        {
            InitializeComponent();
            this.DataContext = new CheckTableViewModel(this);
        }

        public void Init()
        {
            var title = new List<string>()
            {
                "序号",
                "检查井类型",
                "材质",
                "单位",
                "数量",
                "其中非道路下数量",
                "完好数量",
                "井盖井缺失数量",
                "井内有杂物数量",
                "井内有缺陷数量",
                "盖框突出或缺损数量",
                "井室周围填土有沉降",
                "备注"
            };
            var title2 = new List<string>() {
                "铸钢",
                "聚酯化合物",
                "铸铁",
                "砼",
                "塑料",
            };
            var row = 12;
            for (int i = 0; i < row; i++)
            {
                this.table.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });

            }
            for (int i = 0; i < title.Count; i++)
            {
                this.table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(170) });
            }

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < title.Count; j++)
                {
                    var label = new Label();
                    label.HorizontalContentAlignment = HorizontalAlignment.Center;
                    label.VerticalContentAlignment = VerticalAlignment.Center;
                    label.FontSize = 13;

                    var border = new Border();
                    border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                    border.BorderThickness = new Thickness(1, 1, 0, 0);

                    Grid.SetRow(label, i);
                    Grid.SetColumn(label, j);

                    Grid.SetRow(border, i);
                    Grid.SetColumn(border, j);

                    if (i < 2)
                    {
                        label.Background = new SolidColorBrush(Color.FromRgb(247, 248, 251));

                    }

                    if (i == 0 && j == 0)
                    {
                        //设置表名称
                        label.Content = "检查井检查情况汇总表";
                        Grid.SetColumnSpan(label, title.Count);
                        this.table.Children.Add(label);
                    }
                    else if (i == 0)
                    {
                        border.BorderThickness = new Thickness(0, 1, 0, 0);
                    }




                    if (i == 1 )
                    {
                        label.Content = title[j];
                        this.table.Children.Add(label);
                    }

                    
                    //第一行
                    if (i == 2 && j == 0)
                    {
                        label.Content = "1";
                        Grid.SetRowSpan(label, 5);
                        this.table.Children.Add(label);
                    }
                    else if (i > 2 && i< 7 && j == 0)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    if (i == 2 && j == 1)
                    {
                        label.Content = "雨水口";
                        Grid.SetRowSpan(label, 5);
                        this.table.Children.Add(label);
                    }
                    else if (i > 2 && i < 7 && j == 1)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    if (i >= 2 && i < 7 && j == 2)
                    {
                        label.Content = title2[i-2];
                        this.table.Children.Add(label);
                    }

                    //第二行
                    if (i == 7 && j == 0)
                    {
                        label.Content = "2";
                        Grid.SetRowSpan(label, 5);
                        this.table.Children.Add(label);
                    }
                    else if (i > 7  && j == 0)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    if (i == 7 && j == 1)
                    {
                        label.Content = "检查井";
                        Grid.SetRowSpan(label, 5);
                        this.table.Children.Add(label);
                    }
                    else if (i >  7 && j == 1)
                    {
                        border.BorderThickness = new Thickness(1, 0, 0, 0);
                    }

                    if (i >= 7  && j == 2)
                    {
                        label.Content = title2[i - 7];
                        this.table.Children.Add(label);
                    }
                    this.table.Children.Add(border);
                }
            }

            //补边框
            for (int i = 0; i < row; i++)
            {
                var border = new Border();
                border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                border.BorderThickness = new Thickness(0, 0, 1, 0);
                Grid.SetRow(border, i);
                Grid.SetColumn(border, title.Count - 1);
                this.table.Children.Add(border);
            }
            for (int i = 0; i < title.Count; i++)
            {
                var border = new Border();
                border.BorderBrush = new SolidColorBrush(Color.FromRgb(230, 232, 243));
                border.BorderThickness = new Thickness(0, 0, 0, 1);
                Grid.SetRow(border, row - 1);
                Grid.SetColumn(border, i);
                this.table.Children.Add(border);
            }
        }
    }
}
